<?php
  include_once('../conn.php');
  if(!isset($_SESSION['username'])) {
    alert('登录失效，请重新登录', '../login.php');
  } // 是否登录有效，如数据库中的用户名与当前用户名不一致，则警告无效访问

  // 借阅管理 - 消息提醒
  $sql = "select * from apply where apply_statue = 0";
  $result = mysqli_query($conn, $sql);
  if($row = mysqli_num_rows($result) > 0) {
    $span = "<span class='layui-badge'>$row</span>";
  } else {
    $span = "";
  }

  // 权限设置
  function limits($conn, $limits) {
    $username = $_SESSION['username'];
    $sql = "select * from user where username = '$username' and limits like '%".$limits."%'";
    // echo $sql;
    $result = mysqli_query($conn, $sql);
    if(mysqli_num_rows($result) < 1) {
      alert('没有访问权限', 'index.php');
      exit();
    }
  }
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>图书管理系统</title>
  <link rel="stylesheet" href="../layui/css/layui.css" />
  <script src="../layui/layui.js"></script>
</head>
<body>
  <div class="layui-layout layui-layout-admin">
    <div class="layui-header">
      <div class="layui-logo layui-hide-xs layui-bg-black">图书管理系统</div>
      <!-- 头部区域（可配合layui 已有的水平导航） -->
      <ul class="layui-nav layui-layout-left">
        <!-- 移动端显示 -->
        <li class="layui-nav-item layui-show-xs-inline-block layui-hide-sm" lay-header-event="menuLeft">
          <i class="layui-icon layui-icon-spread-left"></i>
        </li>
        
        <li class="layui-nav-item layui-hide-xs"><a href="index.php">主页</a></li>
      </ul>
      <ul class="layui-nav layui-layout-right">
        <li class="layui-nav-item">
          <a href="../logout.php">
          退出登录
          </a>
        </li>
        <li class="layui-nav-item layui-hide layui-show-md-inline-block">
          <a href="javascript:;">个人中心</a>
          <dl class="layui-nav-child">
            <dd><a href="me_info_list.php">个人信息</a></dd>
            <dd><a href="me_apply_new.php">借阅申请</a></dd>
            <dd><a href="me_apply_list.php">申请列表</a></dd>
            <dd><a href="me_book_list.php">我的图书</a></dd>
          </dl>
        </li>
      </ul>
    </div>
    
    <div class="layui-side layui-bg-black">
      <div class="layui-side-scroll">
        <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
        <ul class="layui-nav layui-nav-tree" lay-filter="test">
          <li class="layui-nav-item layui-nav-itemed">
            <a class="" href="javascript:;">图书管理</a>
            <dl class="layui-nav-child">
              <dd><a href="book_new.php">新增图书</a></dd>
              <dd><a href="book_list.php">图书列表</a></dd>
            </dl>
          </li>
          <li class="layui-nav-item">
            <a href="javascript:;">借阅管理</a>
            <dl class="layui-nav-child">
              <dd><a href="apply_list.php">申请列表<?php echo $span; ?></a></dd>
            </dl>
          </li>
          <li class="layui-nav-item">
            <a href="javascript:;">分类管理</a>
            <dl class="layui-nav-child">
              <dd><a href="category_list.php">分类列表</a></dd>
              <dd><a href="category_new.php">新增分类</a></dd>
            </dl>
          </li>
          <li class="layui-nav-item">
            <a href="javascript:;">位置管理</a>
            <dl class="layui-nav-child">
              <dd><a href="position_list.php">位置列表</a></dd>
              <dd><a href="position_new.php">新增位置</a></dd>
            </dl>
          </li>
          <li class="layui-nav-item">
            <a href="javascript:;">用户管理</a>
            <dl class="layui-nav-child">
              <dd><a href="user_list.php">用户列表</a></dd>
              <dd><a href="user_new.php">新增用户</a></dd>
            </dl>
          </li>
          <li class="layui-nav-item">
            <a href="javascript:;">权限设置</a>
            <dl class="layui-nav-child">
              <dd><a href="limits_list.php">权限管理</a></dd>
            </dl>
          </li>
        </ul>
      </div>
    </div>